package com.googlecode.c4e.ui.adapters;

import java.util.List;

import org.apache.continuum.internal.ConnectionProfileManager;
import org.apache.continuum.model.ConnectionProfile;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;

import com.googlecode.c4e.model.Profile;

public class RootElementAdapter implements IWorkbenchAdapter {

  public Object[] getChildren(Object obj) {
    try {
      List<ConnectionProfile> profiles = ConnectionProfileManager
          .loadConnectionProfiles();
      Profile[] result = new Profile[profiles.size()];
      for (int i = 0; i < profiles.size(); i++) {
        ConnectionProfile p = profiles.get(i);
        result[i] = new Profile(p.getConnectionUrl(), p.getId(), p.getLabel(), p.getUsername(), p.getPassword());
      }

      return result;
    } catch (Exception ce) {
      ce.printStackTrace();
      throw new RuntimeException(ce);
    }
  }

  public ImageDescriptor getImageDescriptor(Object obj) {
    // TODO Auto-generated method stub
    return null;
  }

  public String getLabel(Object obj) {
    // TODO Auto-generated method stub
    return null;
  }

  public Object getParent(Object obj) {
    System.err.println("getParent" + getClass().getName());
    return null;
  }

}
